#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

int main() {
    int m, n;
    cin >> m >> n;
    vector<int> n1(m);
    vector<long long> n2(m + 1);
    for (int i = 0; i < m; i++)
    {
        cin >> n1[i];
    }
    for (int i = 1; i <= m; i++)
    {
        n2[i] = n2[i - 1] + n1[i - 1];
    }
    while (n--)
    {
        int x, y;
        cin >> x >> y;
        cout << n2[y] - n2[x - 1] << endl;
    }
    return 0;
}


int main() {
    int m, n, q;
    cin >> m >> n >> q;
    vector<vector<int>> ret(m, vector<int>(n));
    vector<vector<long long>> board(m + 1, vector<long long>(n + 1));
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> ret[i][j];
        }
    }
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            board[i][j] = ret[i - 1][j - 1] + board[i - 1][j] + board[i][j - 1] - board[i - 1][j - 1];
        }
    }
    while (q--)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << board[x2][y2] - board[x1 - 1][y2] - board[x2][y1 - 1] + board[x1 - 1][y1 - 1] << endl;
    }
    return 0;
}

class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int n = nums.size();
        vector<long long> ret(n + 1);
        for (int i = 1; i <= n; i++)
        {
            ret[i] = ret[i - 1] + nums[i - 1];
        }
        for (int i = 1; i <= n; i++)
        {
            if (ret[n] - ret[i] == ret[i] - nums[i - 1])
            {
                return i - 1;
            }
        }
        return -1;
    }
};

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        long long sum = 1;
        int n = nums.size();
        int k = 0;
        for (int i = 0; i < n; i++)
        {
            if (nums[i])
            {
                sum *= nums[i];
            }
            else
            {
                k++;
            }
        }
        vector<int> ret(n);
        for (int i = 0; i < n; i++)
        {
            if (nums[i] && !k)
            {
                ret[i] = sum / nums[i];
            }
            else if (k > 1)
            {
                ret[i] = 0;
            }
            else if (!nums[i] && k == 1)
            {
                ret[i] = sum;
            }
            else if (k == 1 && nums[i] == 0)
            {
                ret[i] = 0;
            }
        }
        return ret;
    }
};

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        int n = nums.size();
        vector<long long> ret(n + 1);
        for (int i = 1; i <= n; i++)
        {
            ret[i] = ret[i - 1] + nums[i - 1];
        }
        int p = 0;
        for (int i = 1; i <= n; i++)
        {
            if (ret[i] == k)
            {
                p++;
            }
            for (int j = 1; j < i; j++)
            {
                if (ret[i] - ret[j] == k)
                {
                    p++;
                }
            }
        }
        return p;
    }
};

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        hash[0] = 1;
        int sum = 0;
        int ret = 0;
        for (auto s : nums)
        {
            sum += s;
            if (hash.count(sum - k))
            {
                ret += hash[sum - k];
            }
            hash[sum]++;
        }
        return ret;
    }
};

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        int n = nums.size();
        vector<int> ret;
        vector<int> f(n);
        vector<int> g(n);
        f[0] = g[n - 1] = 1;
        for (int i = 1; i < n; i++)
        {
            f[i] = f[i - 1] * nums[i - 1];
        }
        for (int i = n - 2; i >= 0; i--)
        {
            g[i] = g[i + 1] * nums[i + 1];
        }
        for (int i = 0; i < n; i++)
        {
            ret.push_back(g[i] * f[i]);
        }
        return ret;
    }
};

class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        int ret = 0;
        int sum = 0;
        hash[0] = 1;
        for (auto s : nums)
        {
            sum += s;
            int n = (sum % k + k) % k;
            if (hash.count(n))
            {
                ret += hash[n];
            }
            hash[n]++;
        }
        return ret;
    }
};